<?php

namespace catchAdmin\system\controller;

use app\common\lib\Redis;
use app\common\lib\ZhyxMongo;
use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\system\model\FieldDic as FieldDicModel;
use think\model\concern\SoftDelete;
use think\Response;

class FieldDic extends CatchController
{


    protected $fieldDicModel;

    /**
     *
     * @time 2023/12/13 11:10
     * @param FieldDicModel $fieldDicModel
     * @return mixed
     */
    public function __construct(FieldDicModel $fieldDicModel)
    {
        $this->fieldDicModel = $fieldDicModel;
    }

    /**
     *
     * @time 2023/12/13 11:10
     * @return Response
     */
    public function index(): Response
    {
        $collection = ZhyxMongo::getInstance()->setCollection('patient_record');



        return CatchResponse::paginate($this->fieldDicModel->getList());
    }

    /**
     *
     * @time 2023/12/13 11:10
     * @param Request $request
     * @return Response
     */
    public function save(Request $request): Response
    {
        $postData = $request->except(["id"]);

        return CatchResponse::success($this->fieldDicModel->save($postData));
    }

    /**
     *
     * @time 2023/12/13 11:10
     * @param $id
     * @return Response
     */
    public function read($id): Response
    {
        return CatchResponse::success($this->fieldDicModel->findBy($id));
    }

    /**
     *
     * @time 2023/12/13 11:10
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update($id, Request $request): Response
    {
        $postData = $request->post();

        return CatchResponse::success($this->fieldDicModel->updateBy($id, $postData));
    }

    /**
     *
     * @time 2023/12/13 11:10
     * @param $id
     * @return Response
     */
    public function delete($id): Response
    {

        return CatchResponse::success($this->fieldDicModel->destroy($id));
    }
}